﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Create</title>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery-1.4.4.min.js")' type="text/javascript"></script>
    <link href='@Url.Content("~/Scripts/zTree/css/zTreeStyle/zTreeStyle.css")' rel="stylesheet" type="text/css" />
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.core-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.excheck-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.exedit-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/PageCreater/Calendar/WdatePicker.js")' type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
            $.fn.zTree.init($("#deparentmentTree"), Setting, Tree);
            $("#divRule").hide();
        })
        function SubmitPage() {
            var treeObj = $.fn.zTree.getZTreeObj("rTree");
            var nodes = treeObj.getCheckedNodes(true);
            var ids = "";
            for (var i = 0; i < nodes.length; i++) {
                ids += nodes[i].id + ",";
            }
            var para = $("#nodeID").val() + "," + $("#sltTerm").val() + "," + $("#marks").val() + "," + $("#start").val() + "," + $("#end").val();
            ids = ids.substr(0, ids.length - 1);
            $.post("/Evaluate/Create", { para: para, selectedID: ids }, function () {
                alert("创建成功");
            });
        }
        var Tree = [
			{ id: 1, pid: 0, name: "请选择系部", isParent: true, icon: "../../Scripts/zTree/css/zTreeStyle/img/diy/users.png" }
		];

        var rTree = [
			{ id: 1, pid: 0, name: "请配置规则", isParent: true, icon: "../../Scripts/zTree/css/zTreeStyle/img/diy/users.png" }
		];

        var rSetting = {
            async: {
                enable: true,
                url: "/Evaluate/getRules",
                type: "Get",
                dataType: "json",
                otherParam: { "id": function () { return $("#nodeID").val() } }
            },
            check: {
                enable: true
            },
            callback: {
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                    var treeObj = $.fn.zTree.getZTreeObj("rTree");
                    treeObj.setting.async.enable = false;
                },
                onAsyncError: function (event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
                    alert("加载错误，请联系系统管理员！");
                },
                onCheck: function (event, treeId, treeNode) {
                    if (treeNode.checked == true) {
                        if (treeNode.level == 0) {
                            if (treeNode.children == null) {
                                treeNode.checked = false;
                                alert("请先展开列表！");
                            }
                        }
                    }
                }
            }
        };

        var Setting = {
            async: {
                enable: true,
                url: "/Evaluate/GetOrganizations",
                type: "Get",
                dataType: "json",
                autoParam: ["id", "pid", "name", "level"]
            },
            callback: {
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                },
                onAsyncError: function (event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
                    
                    alert("加载错误，请联系系统管理员！");
                },
                onClick: function (event, treeId, treeNode) {
                    $("#nodeID").val("");
                    $("#nodeID").val(treeNode.id);
                    if (treeNode.level != 0) {
                        $("#depID").val(treeNode.tld);
                        $("#depName").empty();
                        $("#depName").append(treeNode.name);
                    }
                    $.fn.zTree.init($("#rTree"), rSetting, rTree);
                    $("#divRule").show(400);
                }
            }
        };
    </script>
</head>
<body>
    <div>
        <div>
            @Html.ActionLink("返回列表", "Index")
        </div>
        <div style="width: 150px; height: 100%; float: left">
            <ul id="deparentmentTree" class="ztree">
            </ul>
        </div>
        <div style="width: 350px; height: 100%; float: left">
            <table>
                <tr>
                    <td>
                        系部名称
                    </td>
                    <td>
                        <label id="depName">
                            请选择系部
                        </label>
                    </td>
                </tr>
                <tr>
                    <td>
                        请选择学期
                    </td>
                    <td>
                        <select id="sltTerm">
                            <option value="0" selected="selected">---请选择---</option>
                            <option value="1">第一学期</option>
                            <option value="2">第二学期</option>
                            <option value="3">第三学期</option>
                            <option value="4">第四学期</option>
                            <option value="5">第五学期</option>
                            <option value="6">第六学期</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        分制
                    </td>
                    <td>
                        <input type="text" id="marks" />
                    </td>
                </tr>
                <tr>
                    <td>
                        开始时间
                    </td>
                    <td>
                        <input type="text" id="start" onclick="WdatePicker()" />
                    </td>
                </tr>
                <tr>
                    <td>
                        结束时间
                    </td>
                    <td>
                        <input type="text" id="end" onclick="WdatePicker()" />
                    </td>
                </tr>
            </table>
            <input type="hidden" id="depID" name="depID" />
        </div>
        <div id="divRule" style="width: 350px; height: 100%; float: left">
            <fieldset>
                <legend>请配置规则</legend>
                <ul id="rTree" class="ztree">
                </ul>
            </fieldset>
        </div>
    </div>
    <input type="hidden" id="nodeID" name="nodeID" />
    <div style=" clear:both">
    <input type="button" id="btnSubmit" value="提交" onclick="SubmitPage()" /></div>
</body>
</html>
